﻿/*
Copyright (c) 2009 Vratislav Cermak (vratacermak@gmail.com)
 
This file is part of TeachMe Project. See http://code.google.com/p/teach-me for more information.
 
TeachMe is an open source project. Using of TeachMe is free of charge.
It is distributed under GNU General Public License version 3 (GPLv3).
GPLv3 can be found at http://www.gnu.org/licenses/gpl.html.
 
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE.  See the license for more details.
*/

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;

namespace TeachMe.Application.Drawing
{
    public class EntryDrawingContext
    {
        public BackgroundDrawingContext BackgroundDrawingContext { get; set; }
        public Dictionary<EntryButtonType, ButtonDrawingContext> ButtonDrawingContexts { get; set; }
        public Dictionary<EntryTextType, TextDrawingContext> TextDrawingContexts { get; set; }
        public ProgressDrawingContext ProgressDrawingContext { get; set; }

        public Size Size
        {
            get { return BackgroundDrawingContext.Image.Size; }
        }

        public void Draw(Graphics graphics, DisplayedEntryState displayedEntryState, int progress, bool highlight)
        {
            BackgroundDrawingContext.Draw(graphics);

            foreach (KeyValuePair<EntryButtonType, ButtonDrawingContext> pair in ButtonDrawingContexts)
            {
                pair.Value.Draw(graphics, displayedEntryState.ButtonsStates[pair.Key]);
            }

            switch (displayedEntryState.EntryPhase)
            {
                case DisplayedEntryPhase.Zombie:
                    TextDrawingContexts[EntryTextType.From].Draw(graphics, highlight);
                    break;
                case DisplayedEntryPhase.Counting:
                    TextDrawingContexts[EntryTextType.From].Draw(graphics, highlight);
                    ProgressDrawingContext.Draw(graphics, progress);
                    break;
                case DisplayedEntryPhase.Revelead:
                    TextDrawingContexts[EntryTextType.From].Draw(graphics, highlight);
                    TextDrawingContexts[EntryTextType.To].Draw(graphics, highlight);
                    if (TextDrawingContexts.ContainsKey(EntryTextType.Example))
                    {
                        TextDrawingContexts[EntryTextType.Example].Draw(graphics, highlight);
                    }
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
    }
}
